package usercore.account.service;

import java.util.List;
import java.util.Map;

import usercore.account.models.UserCore;
import usercore.account.models.UserExt;
import usercore.account.models.UserRegister;

public interface UserService {

	public void ping();

	/**
	 * Clear cache
	 * 
	 * @param id
	 * @param clazz
	 */
	public <K, T> void clearCache(K id, Class<T> clazz);

	/**
	 * Query user information list by ids
	 * 
	 * @param ids
	 *            primary key array
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister</em>
	 * @return
	 */
	public <T> List<T> list(final long[] ids, Class<T> clazz);

	/**
	 * Query user information list by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em
	 * @return
	 */
	public <T> List<T> listByFields(Map<String, Object> fields, Class<T> clazz);

	/**
	 * Query user information list by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> List<T> listByFields(Map<String, Object> fields, Class<T> clazz, boolean realTime);

	/**
	 * Query user information list by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @param rowIndex
	 * @param rowSize
	 * @return
	 */
	public <T> List<T> listByFields(Map<String, Object> fields, Class<T> clazz, boolean realTime,
			int rowIndex, int rowSize);

	/**
	 * Query user information list by field
	 * 
	 * @param filed
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> List<T> listByField(String filed, Object value, Class<T> clazz);

	/**
	 * Query user information list by field
	 * 
	 * @param filed
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> List<T> listByField(String filed, Object value, Class<T> clazz, boolean realTime);

	/**
	 * Query user information list by field
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @param rowIndex
	 * @param rowSize
	 * @return
	 */
	public <T> List<T> listByField(String field, Object value, Class<T> clazz, boolean realTime,
			int rowIndex, int rowSize);

	/**
	 * Query user information list by field like
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> List<T> listByFieldLike(String field, Object value, Class<T> clazz);

	/**
	 * Query user information list by field like
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> List<T> listByFieldLike(String field, Object value, Class<T> clazz, boolean realTime);

	/**
	 * Query user information list by field like
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @param rowIndex
	 * @param rowSize
	 * @return
	 */
	public <T> List<T> listByFieldLike(String field, Object value, Class<T> clazz,
			boolean realTime, int rowIndex, int rowSize);

	/**
	 * Query random user information list by field
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param rowSize
	 * @return
	 */
	public <T> List<T> listByFieldRandom(String field, Object value, Class<T> clazz, int rowSize);

	/**
	 * Query user information by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> T selectByFields(Map<String, Object> fields, Class<T> clazz);

	/**
	 * Query user information by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> T selectByFields(Map<String, Object> fields, Class<T> clazz, boolean realTime);

	/**
	 * Query user information by field
	 * 
	 * @param filed
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> T selectByField(String filed, Object value, Class<T> clazz);

	/**
	 * Query user information by field
	 * 
	 * @param filed
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> T selectByField(String filed, Object value, Class<T> clazz, boolean realTime);

	/**
	 * Query user information by id
	 * 
	 * @param id
	 *            primary key
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister</em>
	 * @return
	 */
	public <T> T select(long id, Class<T> clazz);

	/**
	 * Query user information by id
	 * 
	 * @param id
	 *            primary key
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> T select(long id, Class<T> clazz, boolean realTime);

	/**
	 * Query random user information by field
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> T selectByFieldRandom(String field, Object value, Class<T> clazz);

	/**
	 * Insert user information
	 * 
	 * @param t
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> T insert(T t);

	/**
	 * Update user information
	 * 
	 * @param t
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> T update(T t);

	/**
	 * Update user information fields by conditions
	 * 
	 * @param fields
	 *            record fields will be updated, conditions fields are not supported
	 * @param conditions
	 *            record conditions field map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> int updateFields(Map<String, Object> fields, Map<String, Object> conditions,
			Class<T> clazz);

	/**
	 * Update user information fields by id
	 * 
	 * @param id
	 *            primary key
	 * @param fields
	 *            record fields will be updated
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister</em>
	 * @return
	 */
	public <T> T updateFields(long id, Map<String, Object> fields, Class<T> clazz);

	/**
	 * Replace user information
	 * 
	 * @param t
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> T replace(T t);

	/**
	 * Delete user information
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> int deleteByFields(Map<String, Object> fields, Class<T> clazz);

	/**
	 * Delete user information
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>LoginEmail,LoginMobile</em>
	 * @param rowSize
	 * @return
	 */
	public <T> int deleteByFields(Map<String, Object> fields, Class<T> clazz, int rowSize);

	/**
	 * Delete user information
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> int deleteByField(String field, Object value, Class<T> clazz);

	/**
	 * Delete user information
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>LoginEmail,LoginMobile</em>
	 * @param rowSize
	 * @return
	 */
	public <T> int deleteByField(String field, Object value, Class<T> clazz, int rowSize);

	/**
	 * Count by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> int count(Map<String, Object> fields, Class<T> clazz);

	/**
	 * Count by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> int count(Map<String, Object> fields, Class<T> clazz, boolean realTime);

	/**
	 * Exist by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> boolean exist(Map<String, Object> fields, Class<T> clazz);

	/**
	 * Exist by fields
	 * 
	 * @param fields
	 *            record fields map
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> boolean exist(Map<String, Object> fields, Class<T> clazz, boolean realTime);

	/**
	 * Exist by field
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @return
	 */
	public <T> boolean exist(String field, Object value, Class<T> clazz);

	/**
	 * Exist by field
	 * 
	 * @param field
	 *            record field name
	 * @param value
	 *            record field value
	 * @param clazz
	 *            support types:<br>
	 *            <em>UserCore,UserExt,UserRegister,LoginEmail,LoginMobile</em>
	 * @param realTime
	 *            real time query
	 * @return
	 */
	public <T> boolean exist(String field, Object value, Class<T> clazz, boolean realTime);

	/**
	 * Authorize
	 * 
	 * @param type
	 *            0:id 1:emial,2:Mobile
	 * @param username
	 * @param password
	 * @return
	 */
	public boolean authorize(int type, String username, String password);

	public List<UserCore> listUserCoreByUserId(final long[] userIds);

	public List<UserCore> listUserCoreByField(String field, Object value);

	public List<UserCore> listUserCoreByNickname(String nickname);

	public UserCore selectUserCoreByUserId(long userId);

	public UserCore selectRandomUser(int gender);

	public void updateUserCore(UserCore userCore);

	public void updateUserCoreFields(long userId, Map<String, Object> fields);

	public void updateUserCoreField(long userId, String field, Object value);

	public UserExt selectUserExtByUserId(long userId);

	public void updateUserExt(UserExt userExt);

	public void updateUserExtFields(long userId, Map<String, Object> fields);

	public void updateUserExtField(long userId, String field, Object value);

	public List<UserRegister> selectUserRegisterByField(String fieldName, Object value);

	public UserRegister selectUserRegisterByUserId(long userId);

	public void updateUserRegister(UserRegister userRegister);

	public void updateUserRegisterFields(long userId, Map<String, Object> fields);

	public void updateUserRegisterField(long userId, String field, Object value);

	public boolean existLoginEmail(String email);

	public boolean existLoginMobile(String mobile);

	public void insertLoginLog(long userId, int platform, int channelId, int subChannelId,
			String ip, String realIp);

	public int countUsers();

}
